﻿Public Class clsText
    Private _text As String

    Private _tcName As String

    Private _pos As Drawing.PointF
    Private _color As Drawing.Color

    Private _font As Drawing.Font

    Private _space As Single
    Private _amp As Single
    Private _freq As Single

    Private _counter As Single

    Public Sub New(ByVal text As String, ByVal pos As Drawing.PointF, ByVal font As Drawing.Font, ByVal color As Drawing.Color, ByVal space As Single, ByVal amp As Single, ByVal freq As Single)
        _text = text

        _pos = pos
        _color = color

        _font = font

        _space = space
        _amp = amp
        _freq = freq

        _tcName = clsSimTime.AddTimeControl("text")
        _counter = 0.0
    End Sub

    Public Sub Draw(ByRef g As Drawing.Graphics, ByVal text As String)
        ' # Update
        Dim timeDiff As Double = clsSimTime.GetTimeDifference(_tcName)
        _counter += timeDiff
        _counter = _counter Mod ((Math.PI * 2.0) / _freq)


        ' # Render
        Dim x, y As Single
        For i = 0 To text.Length - 1
            x = _pos.X + (i * _space) - (text.Length / 2) * _space
            y = _pos.Y - (_font.Height / 2) + Math.Sin(((i * _space) + _counter) * _freq) * _amp
            g.DrawString(text(i), _font, New SolidBrush(_color), New PointF(x, y))
        Next


    End Sub
    Public Sub Draw(ByRef g As Drawing.Graphics)
        Draw(g, _text)
    End Sub
    Public Sub Remove()
        clsSimTime.RemoveTimeControl(_tcName)
    End Sub
End Class
